<template>
	<div>
		<p class="remarks_p"></p>
		<div class="whiteBg remarks_input" style="position: relative;">
			<input type="text" placeholder="备注名" v-model="nickName">
			<div class="isDone" @click="isDone">完成</div>
		</div>

	</div>
</template>
<script>
	import * as types from '../../vuex/types.js'
	import { mapState } from 'vuex'
    import getData2 from '../../service/getData2.js'
    import {
        Toast,
        Indicator,
        MessageBox
    } from 'mint-ui'
	export default{
	    data(){
	        return{
	            nickName: this.value,
			}
		},
        computed:{
            ...mapState({
                userInfo:state => state.user.userInfo,
            })
        },
		methods:{
            isDone(){
                let number = this.nickName;
                if (number) {
                    if (number.length > 10) {
                        Toast({
                            message: '备注不能超过十个字',
                            duration: 800
                        });
                    } else {
                        window.history.back(-1);
                    }
                } else {
                    window.history.back(-1);
                    //删除好友备注
                    getData2.removeNodes({
                        method: 'delete',
                        data: {
                            "friendId": this.$route.query.friendId,
                            "friendNote": this.nickName,
                            "usrId": this.userInfo.usrId
                        }
                    })
                }
                getData2.friendRemarks({
                    method: 'post',
                    data: {
                        "friendId": this.$route.query.friendId,
                        "friendNote": this.nickName,
                        "usrId": this.$route.query.usrId
                    }//
                }).then(rep => {
                })
            }
		},
		created:function(){
			this.$emit('header-info', {
			  title: '添加备注',
			  isBack: true,
			  isMessage: false,
              isDone: false,
			});
		getData2.friendDetail({
          method:'post',data:{  "friendId": this.$route.query.friendId, "usrId":this.$route.query.usrId}//
		  }).then(rep => {
		    //console.log(rep);
		  if (rep.respCode == '00') {
				this.nickName = rep.content.friendNote;
          }
		})

		},
	}
</script>
<style>
.isDone{
	position:absolute;right:.667rem;top:0rem;color:#ec4e8a;font-size:1.2rem;
}
</style>
